package com.youlu.campus.web.config.filter.utils;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 网络请求工具类
 */
public class ResponseUtils {


    /**
     * 打印输出结果
     *
     * @param response
     * @param o
     */
    public static void writeOutJson(HttpServletResponse response, Object o) {
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        try (PrintWriter out = response.getWriter()) {
            out.println(JSONObject.toJSONString(o));
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
